const test = require('ava')
const path = require('path')

const IntTypes = require(path.resolve(__dirname, '..', 'dist', 'IntTypes.js'))
const PixelTypes = require(path.resolve(__dirname, '..', 'dist', 'PixelTypes.js'))
const readImageLocalFile = require(path.resolve(__dirname, '..', 'dist', 'readImageLocalFile.js'))

test('Test reading a GE4 file', t => {
  const testFilePath = path.resolve(__dirname, '..', 'build', 'ExternalData', 'test', 'Input', '19771.002.001')
  return readImageLocalFile(testFilePath).then(function (image) {
    t.is(image.imageType.dimension, 3, 'dimension')
    t.is(image.imageType.componentType, IntTypes.Int16, 'componentType')
    t.is(image.imageType.pixelType, PixelTypes.Scalar, 'pixelType')
    t.is(image.imageType.components, 1, 'components')
    t.is(image.origin[0], 0.0, 'origin[0]')
    t.is(image.origin[1], 0.0, 'origin[1]')
    t.is(image.origin[2], 0.0, 'origin[2]')
    t.is(image.spacing[0], 1.015625, 'spacing[0]')
    t.is(image.spacing[1], 1.015625, 'spacing[1]')
    t.is(image.spacing[2], 1.5, 'spacing[2]')
    t.is(image.direction.getElement(0, 0), 1.0, 'direction (0, 0)')
    t.is(image.direction.getElement(0, 1), 0.0, 'direction (0, 1)')
    t.is(image.direction.getElement(0, 2), 0.0, 'direction (0, 2)')
    t.is(image.direction.getElement(1, 0), 0.0, 'direction (1, 0)')
    t.is(image.direction.getElement(1, 1), 0.0, 'direction (1, 1)')
    t.is(image.direction.getElement(1, 2), -1.0, 'direction (1, 2)')
    t.is(image.direction.getElement(2, 0), 0.0, 'direction (2, 0)')
    t.is(image.direction.getElement(2, 1), -1.0, 'direction (2, 1)')
    t.is(image.direction.getElement(2, 2), 0.0, 'direction (2, 2)')
    t.is(image.size[0], 4, 'size[0]')
    t.is(image.size[1], 4, 'size[1]')
    t.is(image.size[2], 1, 'size[2]')
    t.is(image.data.length, 16, 'data.length')
    t.is(image.data[10], 80, 'data[10]')
  })
})

test('Test reading a GE5 file', t => {
  const testFilePath = path.resolve(__dirname, '..', 'build', 'ExternalData', 'test', 'Input', '113766.003.001')
  return readImageLocalFile(testFilePath).then(function (image) {
    t.is(image.imageType.dimension, 3, 'dimension')
    t.is(image.imageType.componentType, IntTypes.Int16, 'componentType')
    t.is(image.imageType.pixelType, PixelTypes.Scalar, 'pixelType')
    t.is(image.imageType.components, 1, 'components')
    t.is(image.origin[0], -125, 'origin[0]')
    t.is(image.origin[1], 105, 'origin[1]')
    t.is(image.origin[2], 144, 'origin[2]')
    t.is(image.spacing[0], 1.015625, 'spacing[0]')
    t.is(image.spacing[1], 1.015625, 'spacing[1]')
    t.is(image.spacing[2], 3, 'spacing[2]')
    t.is(image.direction.getElement(0, 0), 1.0, 'direction (0, 0)')
    t.is(image.direction.getElement(0, 1), -0.0, 'direction (0, 1)')
    t.is(image.direction.getElement(0, 2), 0.0, 'direction (0, 2)')
    t.is(image.direction.getElement(1, 0), -0.0, 'direction (1, 0)')
    t.is(image.direction.getElement(1, 1), -0.0, 'direction (1, 1)')
    t.is(image.direction.getElement(1, 2), 1.0, 'direction (1, 2)')
    t.is(image.direction.getElement(2, 0), 0.0, 'direction (2, 0)')
    t.is(image.direction.getElement(2, 1), -1.0, 'direction (2, 1)')
    t.is(image.direction.getElement(2, 2), -0.0, 'direction (2, 2)')
    t.is(image.size[0], 4, 'size[0]')
    t.is(image.size[1], 4, 'size[1]')
    t.is(image.size[2], 1, 'size[2]')
    t.is(image.data.length, 16, 'data.length')
    t.is(image.data[10], 80, 'data[10]')
  })
})

test('Test reading a GEAdw file', t => {
  const testFilePath = path.resolve(__dirname, '..', 'build', 'ExternalData', 'test', 'Input', 'I.001')
  return readImageLocalFile(testFilePath).then(function (image) {
    t.is(image.imageType.dimension, 3, 'dimension')
    t.is(image.imageType.componentType, IntTypes.Int16, 'componentType')
    t.is(image.imageType.pixelType, PixelTypes.Scalar, 'pixelType')
    t.is(image.imageType.components, 1, 'components')
    t.is(image.origin[0], 0, 'origin[0]')
    t.is(image.origin[1], 0, 'origin[1]')
    t.is(image.origin[2], 0, 'origin[2]')
    t.is(image.spacing[0], 0.625, 'spacing[0]')
    t.is(image.spacing[1], 0.625, 'spacing[1]')
    t.is(image.spacing[2], 1.5, 'spacing[2]')
    t.is(image.direction.getElement(0, 0), 1.0, 'direction (0, 0)')
    t.is(image.direction.getElement(0, 1), 0.0, 'direction (0, 1)')
    t.is(image.direction.getElement(0, 2), 0.0, 'direction (0, 2)')
    t.is(image.direction.getElement(1, 0), 0.0, 'direction (1, 0)')
    t.is(image.direction.getElement(1, 1), 0.0, 'direction (1, 1)')
    t.is(image.direction.getElement(1, 2), -1.0, 'direction (1, 2)')
    t.is(image.direction.getElement(2, 0), 0.0, 'direction (2, 0)')
    t.is(image.direction.getElement(2, 1), -1.0, 'direction (2, 1)')
    t.is(image.direction.getElement(2, 2), 0.0, 'direction (2, 2)')
    t.is(image.size[0], 4, 'size[0]')
    t.is(image.size[1], 4, 'size[1]')
    t.is(image.size[2], 1, 'size[2]')
    t.is(image.data.length, 16, 'data.length')
    t.is(image.data[10], 80, 'data[10]')
  })
})
